home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / amos / amoslist-0195.lzh / AMOSLIST / text0072.txt < prev    next >
Encoding:
Text File  |  1995-02-01  |  2.2 KB  |  77 lines

  1. Here's a little proc I made today in 15 mins.
  2. It was made because the JD_Lib's input-command crashed my machine
  3. every time I used it, and I missed the editing facilities (cursor key/del 
  4. support and default string).
  5.  
  6. Note: You can't give strings with spaces at the end of line...
  7. like "asdsadsada      ", the param$ will contain
  8.      "asdsadsada".
  9.  
  10. Procedure _INPUT[X,Y,_DEF$,_MAXLEN,_MOUSE]
  11.    'This proc was made by <veijalai@cc.lut.fi>
  12.    'X,Y     - coordinates 
  13.    '_DEF$   - Default string
  14.    '_MAXLEN - Size of the "text box" in characters
  15.    '_MOUSE  - is this is set to non-zero value, mouse is enabled  
  16.    'The last character in "textbox" is always Space.
  17.    'The proc uses current curs on/off and pen/paper settings
  18.    '
  19.    Print At(X,Y)+Space$(_MAXLEN);
  20.    Locate X,Y
  21.    LL=Min(Len(_DEF$),_MAXLEN)
  22.    XL=LL+1
  23.    'Expand the string to _MAXLEN using spaces 
  24.    TT$=Left$(_DEF$,_MAXLEN)+Space$(_MAXLEN-LL)
  25.    Mid$(TT$,_MAXLEN,1)=" "
  26.    Print At(X,Y)+TT$;
  27.    Repeat 
  28.       Multi Wait 
  29.       I$=Inkey$
  30.       'Mouse 
  31.       If _MOUSE and Mouse Key=1
  32.          If Y Text(Y Screen(Y Mouse))=Y
  33.             XL=X Text(X Screen(X Mouse))-X+1
  34.          End If 
  35.       End If 
  36.       'Cursor keys 
  37.       For Z=78 To 79
  38.          If Key State(Z)
  39.             Add XL,1-(Z-78)*2
  40.             Repeat : Multi Wait : Until Not Key State(Z)
  41.          End If 
  42.       Next 
  43.       'Backspace / Delete
  44.       For Z=65 To 70 Step 5
  45.          If Key State(Z)
  46.             If Z=65 and XL>1
  47.                Dec XL
  48.             End If 
  49.             For ZZ=XL To _MAXLEN-1
  50.                Mid$(TT$,ZZ,1)=Mid$(TT$,ZZ+1,1)
  51.             Next 
  52.             Print At(X,Y)+TT$;
  53.             Repeat : Multi Wait : Until Not Key State(Z)
  54.          End If 
  55.       Next 
  56.       'Check da boundaries 
  57.       If XL<1 Then XL=1
  58.       If XL>_MAXLEN Then XL=_MAXLEN
  59.       Locate X+XL-1,Y
  60.       If I$<>"" and XL<_MAXLEN
  61.          If Asc(I$)>31
  62.             Print I$;
  63.             Mid$(TT$,XL,1)=I$
  64.             Inc XL
  65.          Else 
  66.             Clear Key 
  67.          End If 
  68.       End If 
  69.    Until Key State(68) or Key State(67)
  70.    'Remove unnecessary spaces from the end
  71.    While Right$(TT$,1)=" "
  72.       TT$=Left$(TT$,Len(TT$)-1)
  73.    Wend 
  74.    Clear Key 
  75. End Proc[TT$]
  76.  
  77.